function showUser(){
    let userNaw = JSON.parse(localStorage.getItem('userNaw'))||{}
    // console.log(userNaw[0].username);
    if(userNaw.username){
        $('.outName').html(`用户名：<a href="#">${userNaw.username}</a>|
        <a href="http://127.0.0.1:5555/%E7%86%8A%E7%8C%AB%E4%BC%98%E9%80%89/src/pages/value.html" class='break'>注销</a>`)
    }else{
        $('.outName').html(`<a href="http://127.0.0.1:5555/%E7%86%8A%E7%8C%AB%E4%BC%98%E9%80%89/src/pages/loading.html">登录|注册</a>`)
    }
    $('.break').on('click',function(){
        localStorage.removeItem('userNaw')
    })
}
showUser()
function back(){
    $('.back').on('click',function(){
        var timer = setInterval(function () {
            document.documentElement.scrollTop=document.documentElement.scrollTop-40
            if(document.documentElement.scrollTop<=0){
                clearInterval(timer)
            }
            },10)
    })
}
back()
//点击图片跳转首页
function turn() {
    location.href = `http://127.0.0.1:5555/%E7%86%8A%E7%8C%AB%E4%BC%98%E9%80%89/src/pages/index.html`
}
//导航
function navList() {
    $('.navUl>li').on('mouseover', function () {
        $('.navUl>li').removeClass('active')
        $(this).addClass('active')
    })
    $('.navUl>li').on('mouseout', function () {
        $('.navUl>li').removeClass('active')
    })
}
navList()
//商品列表功能
function productList() {
    getMoreProduct()

    function list(pageNo) {
        let startNum = pageNo * 10
        $.ajax({
            url: 'http://www.xiongmaoyouxuan.com/api/sub_column/174/items?start=' + startNum,
            type: 'get',
            success: function (data) {
                // console.log(data);
                showList(data.data.list)
            },
            error: function (error) {
                console.log(error);
            }
        })
    }
    let listAll = []

    function showList(item) {
        let proList = item.splice(0, 4)
        listAll = [...listAll, ...proList]
        let m = ``
        for (let i = 0; i < listAll.length; i++) {
            m += `<div class="product" onclick='move(${listAll[i].id})'>
        <img src=${listAll[i].image} width='276px'>
        <div class='title1'>${listAll[i].title}</div>
        <div class="word">￥${listAll[i].originPrice}</div>
    </div>
        `
        }
        $('.tatol').html(`${m}`)
    }


    //加载更多
    function getMoreProduct() {
        let pageNo = 0
        list(pageNo)
        $('.getMore').click(function () {
            list(++pageNo)
        })
    }
}
productList()
function showListpro(){
    $.ajax({
        url: 'http://www.xiongmaoyouxuan.com/api/column/170',
        type: 'get',
        success: function (data) {
            console.log(data);
            showLi(data.data.subColumns)
        },
        error: function (error) {
            console.log(error);
        }
    })
}
showListpro()
function showLi(arr){
    let n=''
    for(let i=0;i<arr.length;i++){
        n+=`
        <li><a href="#">${arr[i].name}</a></li>
        `
    }
    $('.list').html(n)
    $('.list').children().first().addClass('active')
}
function move(id) {
    location.href = `http://127.0.0.1:5555/%E7%86%8A%E7%8C%AB%E4%BC%98%E9%80%89/src/pages/productdetail.html?id=${id}`
}